<?php

namespace app\admin\dao;

use app\common\model\Chain;
use ShidianUtil\Thinkphp\Dao\DaoTrait;
use think\Collection;

/**
 * ChainDao 数据访问对象
 * Class ChainDao
 * @package app\admin\dao
 * @method Chain findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method Chain insertActive(array $params, array $allow_field = [])
 * @method Chain updateActive(Chain $model, array $params, array $allow_field = [])
 * @method Chain findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method Chain updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(Chain $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ChainDao
{
    use DaoTrait;

    /**
     * @var Chain
     */
    private $baseModel;

    /**
     * ChainDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = Chain::class;
    }

    /**
     * 可选的链路类型
     * @return Collection
     */
    public function selectOptions(): Collection
    {
        return Chain::order('id', 'desc')
                    ->select();
    }

    /**
     * 链路列表
     * @return array
     */
    public function select($page, $page_size): array
    {
        $query = Chain::order('id', 'desc')
                      ->paging($page, $page_size);

        return listOutput($query, $page_size);
    }


}
